#define _CRT_SECURE_NO_WARNINGS 1

int size(int a)
{
    if (a == 0)
        return 0;
    return 1 + size(a /= 10);
}

int reverse(int x) {
    bool symbol = 1;
    int i = 1;
    int n = size(x);
    long sum = 0;
    long t = x;
    if (x < 0)
    {
        symbol = 0;
        t = -t;
    }
    for (i = n - 1; i >= 0; i--)
    {
        sum += (t % 10) * pow(10, i);
        t /= 10;
    }
    if (symbol == 0)
        sum = -sum;
    if (sum > pow(2, 31) - 1 || sum < -pow(2, 31))
        sum = 0;
    return sum;
}